#pragma once

#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QThread>
#include <QtCore/QUrl>
#include "WebBrowser.h"

typedef QPair<QString, int> Tag;

class Tags : public QVector<Tag>
{
public:
	typedef QVector<Tag> __Base;
public:
	Tags(int n = 0) : __Base(n) {}
	QString join(bool keepTag = true) const;
};

class Dictionary : public QHash<QString, QStringList>
{
public:
  typedef QHash<QString, QStringList> __Base;
  typedef __Base::iterator           iterator;
public:
	void load(const QString& fName);
  void save(const QString& fName);
};

class Translator : public QThread
{
	Q_OBJECT
public:
	QString m_html, m_trHtml;
	QUrl m_url;
	WebBrowser* m_browser;
	int m_id;

  static int m_lastID;
	static QVector<Dictionary> m_dic;

	Translator(WebBrowser* browser, const QString& html, const QUrl& url, QObject *parent = 0);
	~Translator();
	void run();

	static QString translateHtml(const QString& html);
	static void loadDictionaries();

	static QString translateText(const QString& text);
	static QString convert(const QString& text);
  static QString makeName(const QString& text);

	static void parseHtml(const QString& html, Tags& tags);
};
